package panels;

import islemler.KullaniciYonet;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;

import javax.swing.JOptionPane;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import panels.KullaniciSilPaneli.SilmeIslemi;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class KullaniciGuncellePaneli extends javax.swing.JPanel {
	private JTextField kullaniciAdiField;
	private JPasswordField sifreField;
	private JPasswordField yeniSifreField;
	private JLabel yeniSifreLabel;
	private JButton degisButonu;
	private JLabel eskiSifreLabel;
	private JLabel kullaniciAdiLabel;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new KullaniciGuncellePaneli());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public KullaniciGuncellePaneli() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			setPreferredSize(new Dimension(400, 300));
			{
				kullaniciAdiField = new JTextField();
			}
			{
				kullaniciAdiLabel = new JLabel();
				kullaniciAdiLabel.setText("Kullanici adi :");
			}
			{
				degisButonu = new JButton();
				degisButonu.setText("DEG\u0130ST\u0130R");
				degisButonu.addActionListener(new GuncellemeIslemi());
			}
			{
				sifreField = new JPasswordField();
			}
			{
				eskiSifreLabel = new JLabel();
				eskiSifreLabel.setText("Eski sifre :");
			}
			{
				yeniSifreField = new JPasswordField();
			}
			{
				yeniSifreLabel = new JLabel();
				yeniSifreLabel.setText("Yeni sifre :");
			}
				thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
					.addContainerGap(54, 54)
					.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(kullaniciAdiField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
					    .addComponent(kullaniciAdiLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(35)
					.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(sifreField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					    .addComponent(eskiSifreLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(34)
					.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(yeniSifreField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					    .addComponent(yeniSifreLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(37)
					.addComponent(degisButonu, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(53, Short.MAX_VALUE));
				thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
					.addContainerGap(57, 57)
					.addGroup(thisLayout.createParallelGroup()
					    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
					        .addComponent(yeniSifreLabel, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
					        .addGap(55))
					    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
					        .addComponent(eskiSifreLabel, GroupLayout.PREFERRED_SIZE, 107, GroupLayout.PREFERRED_SIZE)
					        .addGap(23))
					    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
					        .addComponent(kullaniciAdiLabel, GroupLayout.PREFERRED_SIZE, 107, GroupLayout.PREFERRED_SIZE)
					        .addGap(23))
					    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
					        .addGap(56)
					        .addComponent(degisButonu, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE)))
					.addGroup(thisLayout.createParallelGroup()
					    .addGroup(thisLayout.createSequentialGroup()
					        .addComponent(yeniSifreField, GroupLayout.PREFERRED_SIZE, 140, GroupLayout.PREFERRED_SIZE))
					    .addGroup(thisLayout.createSequentialGroup()
					        .addComponent(sifreField, GroupLayout.PREFERRED_SIZE, 140, GroupLayout.PREFERRED_SIZE))
					    .addGroup(thisLayout.createSequentialGroup()
					        .addComponent(kullaniciAdiField, GroupLayout.PREFERRED_SIZE, 140, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(73, Short.MAX_VALUE));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public void kullIslemPanel() {
		this.removeAll();
		KullaniciIslemPanel islemPanel = new KullaniciIslemPanel();
		islemPanel.setSize(600, 400);
		add(islemPanel);
		this.revalidate();
		this.repaint();
		islemPanel.revalidate();
		islemPanel.repaint();
	}
	
public class GuncellemeIslemi implements ActionListener{
		
		@Override
		public void actionPerformed(ActionEvent e) {
			KullaniciYonet kullYonet = new KullaniciYonet();
			kullYonet.guncelle(kullaniciAdiField.getText(), new String(sifreField.getPassword()),new String(yeniSifreField.getPassword()));
			if(kullYonet.getBasariKodu() == 0){
			JOptionPane.showMessageDialog(null, "basarili bir sekilde guncellendi.");
			kullIslemPanel();
			}
			else
				JOptionPane.showMessageDialog(null, "guncellenemedi.");
		}
	}
}
